<?php

namespace app\admin\model;

use fast\Tree;

class Materialcate extends Base
{
    // 表名
    protected $name = 'bd_material_g';



    //属性
    public function marpop()
    {
        return $this->belongsToMany("Matprop",'bd_materialentry','fk_bdl_bd_matprop','fk_bdl_bd_material_g');
    }

    public function getRuleData($wheredata = [])
    {
        $this->model = model('Materialcate');

        $ruleList = $this->model
            ->with(['marpop','modifier','creator','datacenter','forg'])
            ->where($wheredata)
            ->order('id','asc')
            ->select();
        Tree::instance()->init($ruleList, 'fk_bdl_super');

        $rulelist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'fname');

        $ruledata = [0 => __('None')];
        foreach ($rulelist as $k => $v)
        {
            $ruledata[$v['id']] = $v['fname'];
        }

        return [
            'ruledata'  => $ruledata,
            'rulelist' => $rulelist,
        ];
    }



}
